package #(package);

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;
import com.juran.common.util.PageResult;
import #(modelPackageName);
import #(dtoPackageName)Dto;
import #(packageBase).service.#(className)Service;

import com.lianheng.cms.common.dto.BaseSearchDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
/**
* #(className) 管理
* 描述：
*/
@Slf4j
@Service
public class #(className)ServiceImpl implements #(className)Service  {


    private final #(className) dao = new #(className)().dao();


    /**
    * 列表-分页
    */
    public PageResult #(classNameSmall)Paginate(BaseSearchDto searchDto) {
        SqlPara sqlPara = Db.getSqlPara("#(classNameSmall)Paginate", searchDto);
        Page<#(className)> #(classNameSmall)Page =dao.paginate(searchDto.getPageNumber(), searchDto.getPageSize(),sqlPara);
        LinkedList #(classNameSmall)s = new LinkedList<>();
        #(classNameSmall)Page.getList().forEach(#(classNameSmall) -> {
            #(classNameSmall)s.add(#(classNameSmall));
        });
        return new PageResult(searchDto.getPageNumber(), searchDto.getPageSize(), #(classNameSmall)s,  #(classNameSmall)Page.getTotalRow());
    }

    /**
    * 保存
    */
    public void  #(classNameSmall)Save(#(className) #(classNameSmall)) {
       #(classNameSmall).save();
    }

    /**
    * 更新
    */
    public void  #(classNameSmall)Update(#(className) #(classNameSmall)) {
       #(classNameSmall).update();
    }

    /**
    * 查询
    */
    public #(className)  #(classNameSmall)FindById(Long #(classNameSmall)Id) {
       return dao.findFirst("select * from #(tableName) where id=?", #(classNameSmall)Id);
    }

    /**
    * 删除
    */
    public void  #(classNameSmall)Delete(Long #(classNameSmall)Id) {
       Db.update("delete from #(tableName) where id=?", #(classNameSmall)Id);
    }


}